package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import model.IState;

/**
 * Responsible for deserialization of IState objects
 */
public class Load {
	
	/**
	 * Inflates the IState object from a file 
	 * @param file the file to deserialize
	 * @return the deserialized file
	 * @throws ClassNotFoundException if given a bad file path (issue50)
	 */
	public IState readFromFile(String file) throws ClassNotFoundException{

		ObjectInputStream inputStream = null;
		Object content = null;

		try{
			inputStream = new ObjectInputStream(new FileInputStream(file));
			content = inputStream.readObject();

		} catch (FileNotFoundException ex){
			ex.printStackTrace();
		} catch (IOException ex){
			ex.printStackTrace();
		} finally {
			try{
				if(inputStream != null){
					inputStream.close();
				}
			} catch (IOException ex){
				ex.printStackTrace();
			}
		}

		IState state = (IState) content;
		
		return state;
	} //ReadFromFile
}